package com.acwing.partition11;

import java.io.*;

/**
 * @author `RKC`
 * @date 2021/12/23 16:38
 */
public class AC1077皇宫看守 {

    private static final int N = 1510, INF = 0x3f3f3f3f;
    private static int[] head = new int[N], weight = new int[N];
    private static boolean[] notRoot = new boolean[N];
    private static int[][] element = new int[N][2], dp = new int[N][3];
    private static int index = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] s = reader.readLine().split("\\s+");
        int n = Integer.parseInt(s[0]), root = 0;
        for (int i = 1; i <= n; i++) head[i] = -1;
        for (int k = 0; k < n; k++) {
            s = reader.readLine().split("\\s+");
            int u = Integer.parseInt(s[0]), w = Integer.parseInt(s[1]), c = Integer.parseInt(s[2]);
            weight[u] = w;
            for (int i = 3, j = 0; j < c; j++, i++) {
                int v = Integer.parseInt(s[i]);
                notRoot[v] = true;
                createEdge(u, v);
            }
        }
        for (int i = 1; i <= n; i++) {
            if (!notRoot[i]) {
                root = i;
                break;
            }
        }
        dfs(root);
        writer.write(Math.min(dp[root][1], dp[root][2]) + "\n");
        writer.flush();
    }

    private static void dfs(int u) {
        dp[u][2] = weight[u];
        int sum = 0;
        for (int i = head[u]; i != -1; i = element[i][1]) {
            int v = element[i][0];
            dfs(v);
            //当前节点u不放守卫能被父节点看到，父节点已经覆盖了u节点，v节点可以被v的子节点看到，也可以在v上放置一个守卫
            dp[u][0] += Math.min(dp[v][1], dp[v][2]);
            //当前节点u放置守卫，此时v节点可以放，也可以不放被自己的子节点看到，还可以不能被自己的子节点看到但是可以被u看到
            dp[u][2] += Math.min(Math.min(dp[v][2], dp[v][1]), dp[v][0]);
            sum += Math.min(dp[v][1], dp[v][2]);
        }
        dp[u][1] = INF;
        for (int i = head[u]; i != -1; i = element[i][1]) {
            int v = element[i][0];
            //如果u是由子节点看守，那么所有u的子节点v都不可能是由父节点看守的情况，且每个子节点都得到了守卫，至少有一个子节点处放置了守卫
            dp[u][1] = Math.min(dp[u][1], sum - Math.min(dp[v][1], dp[v][2]) + dp[v][2]);
        }
    }

    private static void createEdge(int u, int v) {
        int[] curr = element[index];
        curr[0] = v;
        curr[1] = head[u];
        head[u] = index++;
    }
}
